<?php
require_once 'classes/Login.php';
require_once 'classes/Employer.php';
$Login = new Login;
$Employer = new Employer;
$total_count = $Employer->count_all();

if(!$Login->verify())
{
    header('Location:index.php');
}
if(($Login->superUser($_SESSION['employerID']))) {
	$companyName = $Login->getCompanyName($_SESSION['employerID']);
	$employerInfo = $Employer->getEmployerDetails();
	$isOne = $Employer->isLast();
	include 'includes/header.inc.php';
	?>
<script language="JavaScript">
function verifyPromote()
{
 return confirm('You sure you want to promote user?');
}

function verifyDemote()
{
 return confirm('You are about to demote this user, are you sure you want to continue?');
}

function verifyDelete()
{
 return confirm('You sure you want to remove user?');
}
</script>
<a href="/sandbox1/myAccount.php">My Account</a>&nbsp;|&nbsp;
<a href="/sandbox1/jobCategories.php">Job Categories</a>&nbsp;|&nbsp;
<a href="inactiveEmployers.php">Inactive Employers</a>
	<div id="form">
		<h2>Active Employers</h2>
			<fieldset id="employerUpdateForm">
			<form enctype="multipart/form-data" method="post" action="process.php">
			<?php
			if(!empty($employerInfo))
			{
				echo '        <table class="postingsTable">
									<thead>
										<tr>
											<th scope="col" id="postCompany">Company Name</th>
											<th scope="col" id="emailPost">Contact Email</th>
											<th scope="col" id="adminPost">Admin</th>
										    <th scope="col" id="adminPost">DEL</th>
										</tr>
									</thead>
									<tbody>';
				for($i=0;$i<count($employerInfo);$i++)
				{
					if($i % 2 != 0)
						$rowcolor = "#FFFFFF";
					else
						$rowcolor = "#F4F4FF";
					
					echo '
									
										<tr bgcolor="' . $rowcolor .'">
											<td class="empCompany">
											<a href="specificPostings.php?id='.$employerInfo[$i]['id'].'" >'
											.$employerInfo[$i]['companyName'].'</a></td>
											<td class="empEmail">'.$employerInfo[$i]['email'].'</td>
											<td class="empAdmin">'; ?> 
											
											
											<?php if($employerInfo[$i]['isAdmin']) { /*Is Admin?*/
														if($isOne) { /*Is the last Admin?*/ ?> 
                                            				<img src="media/images/key.png"/>
                                                <?php   } else { ?>
                                                        <a href="userProcess.php?action=demoteUser&id=<?php echo $employerInfo[$i]['id']; ?>" 
                                                        onclick="return verifyDemote()">
                                                        <img src="/sandbox1/media/images/key.png" title="Promote User"/></a>
											<?php       }
													} else { ?>
                                            <a href="userProcess.php?action=promoteUser&id=<?php echo $employerInfo[$i]['id']; ?>" onclick="return verifyPromote()">
                                            <img src="/sandbox1/media/images/promote.png" title="Promote User"/></a>
											 <?php }
									   
										echo '</td>
											<td class="empActions">'; ?>
											
                                            <?php if($employerInfo[$i]['isAdmin']) { ?>
											&nbsp;
											<?php } else { ?>
											<a href="userProcess.php?action=removeUser&id=<?php echo $employerInfo[$i]['id']; ?>" 
											id="removeUser" onclick="return verifyDelete()">
											<img src="/sandbox1/media/images/not.png" title="Remove User"/></a>
											<?php } ?>
									<?php	echo '</td>
										</tr>'; ?>
			<?php	}
				 echo'               </tbody>
								</table>'; ?>
			<?php }
			else
			{
				echo '<div id="noResults">You currently have no employers.</div>'; ?>
		<?php	} ?>
			<p>
			  <?php /*<input type="submit" name="previewPost" id="previewPost" class="button" value="Save Changes" />*/ ?>
			</p>
			</form>
			</fieldset>
	</div> <?php 
}
else {  header('Location:index.php'); }    ?>
        
        <?php include 'includes/footer.inc.php';
        ?>
		